/**
 * udes.ds.rmi
 * Constant.java
 * 3 sept. 08
 */
package ift605.EquationWithAgent.server;

import javax.naming.directory.InvalidAttributesException;

import udes.ds.agent.AbstractEquation;

// The unknown equation
public class MarvinEquation extends AbstractEquation {
	private static final long	 serialVersionUID	= 1L;
	private double  _value = 42;
	private int _exponent = 1;

	public MarvinEquation() {
		super();
	}

	public double getValue() {
		return _value;
	}
	
	/**   
	 * @see udes.ds.rmi.hw.Equation#getFunctionValue(double)       
	 */
	public double getFunctionValue(double x) {
		return _value*Math.pow(x, _exponent);
	}

	/**   
	 * @see udes.ds.rmi.hw.AbstractEquation#getUserReadableString()      
	 */
	public String getUserReadableString() {
		return _value + "*x";
	}

	@Override
	public Object[] getValues() {
		return new Object[]{_value, _exponent};
	}
	
	@Override
	public void setValues(Object[] aObjects) throws InvalidAttributesException 
	{
		int i = 0;
		if (aObjects.length == 2)
		{
			if(aObjects[0] instanceof Double)	
			{
				_value = (Double)aObjects[0];
				++i;
			}
			if(aObjects[1] instanceof Integer)	
			{
				_exponent = (Integer)aObjects[1];
				++i;
			}
		}
		
		if(i != 2)
		{
			throw new InvalidAttributesException();
		}
	}
	
}
